import java.security.PrivateKey;
import java.util.*;

class NumberContainers {
    private Map<Integer, Set<Integer>> map;
    private Map<Integer, Integer> map2;

    public NumberContainers() {
        map = new HashMap<>();
        map2 = new HashMap<>();
    }
    
    public void change(int index, int number) {
      if(map2.containsKey(index)) {
        int oldNumber = map2.get(index);
        Set<Integer> oldSet = map.getOrDefault(oldNumber, new HashSet<>());
        oldSet.remove(index);
        map.put(oldNumber, oldSet);
      }
      map2.put(index, number);
      Set<Integer> set = map.getOrDefault(number, new HashSet<>());
      set.add(index);
      map.put(number, set);
    }
    
    
    public int find(int number) {
        Set<Integer> set = map.getOrDefault(number, new HashSet<>());
        if(set.size() == 0) {
            return -1;
        }
        return Collections.min(set);
    }
    
    public static void main(String[] args) {
      NumberContainers obj = new NumberContainers();
      obj.change(0, 10);
      obj.change(1, 20);
      obj.change(2, 30);
      obj.change(3, 40);
      obj.change(4, 50);
      obj.change(5, 60);
      obj.change(0, 60);
      obj.change(6, 70);
      obj.change(7, 80);
      obj.change(8, 90);
      obj.change(9, 100);
      System.out.println(obj.find(50)); // Output: 4
      System.out.println(obj.find(100)); // Output: 9
      System.out.println(obj.find(10)); // Output: 0
      System.out.println(obj.find(60)); // Output: 0
    }
}
